import http from '@/utils/request'

import IBaseObj from '#/index'

const base = '/dep'

// 获取树形结构部门
const getDepTreeByOid = (oid: string | number, enable = 1) =>
  http({
    url: `${base}/tree/${oid}/enable/${enable}`,
    method: 'get',
  })

const getDepListByOid = (oid: string | number, enable = 1) =>
  http(
    {
      url: `${base}/list/${oid}/enable/${enable}`,
      method: 'get',
    },
    true
  )

const getDepByPage = (data: IBaseObj) =>
  http({
    url: `${base}/page`,
    method: 'post',
    data,
  })

const saveDep = (data: IBaseObj) =>
  http({
    url: `${base}/save`,
    method: 'post',
    data,
  })

const getDepById = (id: string | number) =>
  http({
    url: `${base}/${id}`,
    method: 'get',
  })

// 更新状态
const updateStatus = (data: IBaseObj) =>
  http({
    url: `${base}/enable`,
    method: 'post',
    data,
  })

const delUrl = `${base}`

export default {
  getDepByPage,
  saveDep,
  getDepById,
  delUrl,
  getDepTreeByOid,
  getDepListByOid,
  updateStatus,
}
